package club.dataresources.service.impl;

import club.dataresources.entity.Admin;
import club.dataresources.entity.AdminExample;
import club.dataresources.mapper.AdminMapper;
import club.dataresources.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @create 2018-10-30 20:38
 **/
@Service
public class AdminServiceImpl implements AdminService{

    @Autowired
    private AdminMapper adminMapper;

    //后台管理员登录
    @Override
    public Admin adminLogin(Admin admin) throws Exception {

        AdminExample example = new AdminExample();
        AdminExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(admin.getUsername());
        criteria.andPasswordEqualTo(admin.getPassword());
        List<Admin> liAdmin = adminMapper.selectByExample(example);

        if (liAdmin != null && liAdmin.size() == 1) {
            return liAdmin.get(0);
        } else {
            return null;
        }
    }
}
